extends Node2D

const BeamSpeed : int = 1100

enum BeamType{Light, Dark}
var CurrentBeamType : BeamType = BeamType.Light

class ParticleDesc:
	var name : String
	var value : int
	var resource : SpriteFrames
	var trailColor : Color

	func _init(_name: String, _value: int, _resource: SpriteFrames, _trailColor: Color) -> void:
		name = _name
		value = _value
		resource = _resource
		trailColor = _trailColor

var ParticleMap = {
	BeamType.Light : ParticleDesc.new("Light", 1, Preload.Light_Particle_Animation, Color(1, 1, 1, 1)),
	BeamType.Dark : ParticleDesc.new("Dark", 0, Preload.Dark_Particle_Animation, Color(0.08, 0.08, 0.15, 1)),
}

func _create_particle(desc: ParticleDesc, pos: Vector2) -> CharacterBody2D:
	var particle = Preload.ParticleScene.instantiate()

	var shape = RectangleShape2D.new()
	shape.size = desc.resource.get_frame_texture(desc.resource.get_animation_names()[0], 0).get_size()

	particle.init(desc.resource, pos, shape, desc.value, desc.trailColor)
	add_child(particle)

	return particle

func spawn_beam(
	bird_pos : Vector2
) -> CharacterBody2D:
	# Logic of spawning beam

	var beam : CharacterBody2D
	if CurrentBeamType == BeamType.Light:
		beam = _create_particle(ParticleMap[BeamType.Light], bird_pos)
	else:
		beam = _create_particle(ParticleMap[BeamType.Dark], bird_pos)

	var vel = get_window().get_mouse_position() - bird_pos

	beam.velocity = vel.normalized() * BeamSpeed
	return beam

func switch_beam_type() -> void:
	if CurrentBeamType == BeamType.Light:
		CurrentBeamType = BeamType.Dark
	else:
		CurrentBeamType = BeamType.Light
